package com.boco.blch.analysiser.compliance.HW.data;

import com.boco.blch.analysiser.compliance.ComplianceResolved;
import com.boco.blch.analysiser.util.XmlUtil;

/**
 * YARN&MR接口认证安全基线要求项【控制节点】+【数据节点】
 * 【数据节点路径】：
 * 1、查看/opt/huawei/bigdata/etc/2_21_NodeManager/core-site.xml的配置项hadoop.security.authentication的值。
 * 如果配置项目值为 kerberos，则合规；
 * 
 * 
 * 【控制节点路径】：
 * 1、查看/opt/huawei/bigdata/etc/2_21_NodeManager/core-site.xml的配置项hadoop.security.authentication的值。
 * 如果配置项目值为 kerberos，则合规；
 * @author admin
 *
 */
public class BOCO_Yarn_IdentityAuth_InterfaceAuth implements ComplianceResolved {

	private final static String name = "hadoop.security.authentication";
	private final static String value = "kerberos";
	
	@Override
	public int realEchoResolved(String echoResult) {
		/*查看/opt/huawei/Bigdata/etc/2_26_Broker/目录下的ENV_VARS里面的变量：HADOOP_SECURITY_AUTHENTICATION的值应该为：kerberos*/
		int result = FAILED;
		if(echoResult != null && echoResult.length() > 0){
			if(echoResult.indexOf("NodeManager-start") != -1){//数据节点
				String strResult = echoResult.substring(echoResult.indexOf("NodeManager-start")+"NodeManager-start".length(), echoResult.indexOf("NodeManager-end")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("ResourceManager-start") != -1){//控制节点
				String strResult = echoResult.substring(echoResult.indexOf("ResourceManager-start")+"ResourceManager-start".length(), echoResult.indexOf("ResourceManager-end")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("JobHistoryServer-start") != -1){//控制节点
				String strResult = echoResult.substring(echoResult.indexOf("JobHistoryServer-start")+"JobHistoryServer-start".length(), echoResult.indexOf("JobHistoryServer-end")).trim();
				result = getResult(strResult);
			}
		}
		return result;
	}
	
	private int getResult(String echoResult){
		int result = FAILED;
		if(echoResult != null && echoResult.length() > 0){
			String values = XmlUtil.getValueByName(echoResult, name);
			//System.out.println(values);//result = getResult(strResult1);
			if(values!=null && values.equals(value)){
				result = SUCCESS;
			}else{
				result = FAILED;
			}
		}
		return result;
	}
}
